import request from '@/utils/request'

/**
 * 重新渲染的公共方法
 */
export default {
  props: {
    currentItem: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      dOptions: []
    }
  },
  watch: {
    getUrl(nv) {
      if (nv.isNetWork) {
        request({
          url: nv.url,
          method: 'get'
        }).then(res => {
          this.dOptions = res.data;
        })
      }

    }
  },
  computed: {
    getUrl() {
      if (this.currentItem.network) {
        if (this.currentItem.network.dict && this.currentItem.network.dictType) {
          return {
            isNetWork: true,
            url: "/system/dict/data/type/" + this.currentItem.network.dictType
          }
        }
        if (this.currentItem.network.url) {
          return {
            isNetWork: true,
            url: this.currentItem.network.url
          }
        }
      }
      return {
        isNetWork: false,
        url: ""
      }
    },

    /**
     * 配置选项
     */
    options() {
      console.log(this.dOptions)
      if (this.getUrl.isNetWork) {
        return this.dOptions.map(item => {
          item[this.currentItem.optionsLabel] = item.dictLabel;
          item[this.currentItem.optionsValue] = item.dictValue;
          return item;
        })
      }
      return this.currentItem.options
    }
  }
}
